<script setup lang="ts">
import { ref, onMounted } from 'vue'
import Login from './views/Login.vue'
import Home from './views/Home.vue'

// 当前页面
const currentPage = ref<'login' | 'home'>('login')

// 检查是否已登录
const checkLogin = () => {
  const hash = window.location.hash
  
  if (hash === '#/home') {
    currentPage.value = 'home'
  } else {
    currentPage.value = 'login'
  }
}

// 切换页面
const switchPage = (page: 'login' | 'home') => {
  currentPage.value = page
  window.location.hash = page === 'home' ? '#/home' : '#/login'
}

onMounted(() => {
  checkLogin()
  
  // 监听URL变化
  window.addEventListener('hashchange', checkLogin)
})

// 暴露给全局使用
;(window as any).switchPage = switchPage
</script>

<template>
  <div id="app">
    <Login v-if="currentPage === 'login'" />
    <Home v-else-if="currentPage === 'home'" />
  </div>
</template>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  width: 100%;
  min-height: 100vh;
}
</style>
